home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14324 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  71 lines

  1. Path: news.achilles.net!usenet
  2. From: Pascal Lachance <plachance@xtc-com.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: unlucky 13
  5. Date: Fri, 29 Mar 1996 15:21:22 -0500
  6. Organization: Achilles Internet Services, Ottawa, ON
  7. Message-ID: <315C4642.57DA@xtc-com.com>
  8. NNTP-Posting-Host: 205.233.53.187
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (Win95; I)
  13.  
  14. Well I guess 13 is not a lucky number after all, after I run this 
  15. program
  16. it kluncks out at 13. It should start at 20 and then substract one from 
  17. that
  18. until it reaches 0.
  19.  
  20. Does anybody know what is wrong with this ?
  21. If so leave me some mail :)
  22.  
  23. Thanks
  24.  
  25.  
  26. #include <stdio.h>
  27. #include <iostream.h>
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #include <time.h>
  31.  
  32. struct rec {
  33.                                 char name[50];
  34.                                 long money;
  35.                           };
  36.  
  37. void main()
  38. {
  39. FILE *f;
  40. struct rec t_rec;
  41. int x,y,z;
  42. int count;
  43.          //create user
  44.  
  45.          f=fopen("money.dat","w");
  46.          strcpy(t_rec.name,"Joe Bob");
  47.          t_rec.money =20;
  48.          fwrite(&t_rec,sizeof(struct rec),1,f);
  49.          fclose(f);
  50.  
  51.  
  52. while(t_rec.money>0)
  53. {
  54.          f=fopen("money.dat","r");
  55.          fread(&t_rec,sizeof(struct rec),1,f);
  56.          cout << "After Read,Before Sub money = " << t_rec.money << 
  57. "\n";
  58.          t_rec.money -= 1;
  59.          cout << "after Sub money = " << t_rec.money << "\n";
  60.          fclose(f);
  61.          f=fopen("money.dat","w");
  62.          fwrite(&t_rec,sizeof(struct rec),1,f);
  63.          cout << "after write money = " <<t_rec.money << "\n";
  64.          cout << "---------------------------------\n\n";
  65.          fclose(f);
  66.  
  67.  
  68.  
  69. }
  70. } //end main
  71.